/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: jse2303 - Reg3
 * <p>Powered by webrx On 2023-07-18 09:33:01
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reg3 {
    public static void main(String[] args) {

        int i = 0;
        while (true) {
            ++i;
            String str = getStr();
            if (getSum(str) == 100) {
                System.out.println(str + "=100");
                System.out.println(i);
                break;
            }
        }
    }

    public static int getSum(String str) {
        int sum = 0;
        Pattern p = Pattern.compile("-?\\d+");
        Matcher m = p.matcher(str);
        while (m.find()) {
            sum += Integer.parseInt(m.group());
        }
        return sum;
    }

    public static String getStr() {
        StringBuilder sbu = new StringBuilder();
        Random rand = new Random();
        String[] op = {"", "+", "-"};
        for (int i = 1; i < 9; i++) {
            sbu.append(String.format("%d%s", i, op[rand.nextInt(op.length)]));
        }
        sbu.append("9");
        return sbu.toString();
    }
}
